package com.edu.internship.config.mvc;

import com.edu.internship.config.interceprot.UserTokenInterceptor;
import com.edu.internship.glabal.properties.SystemProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import javax.servlet.MultipartConfigElement;

/**
 * code is far away from bug with the animal protecting
 *
 * @author lishiquan
 * @description
 * @date 2022-07-29
 */
@Configuration
public class SpringMvcConfiguration implements WebMvcConfigurer {

    @Resource
    private SystemProperties systemProperties;
    @Resource
    private UserTokenInterceptor userTokenInterceptor;

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation(systemProperties.getTempDirectory());
        return factory.createMultipartConfig();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/ext/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/ext/file/**")
                .addResourceLocations("file:" + systemProperties.getFileDirectory());
    }
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(userTokenInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns("/api/auth/login","/api/captcha");
//    }

}
